import 'package:wanxiang_app/generated/json/base/json_convert_content.dart';
import 'package:wanxiang_app/bean/category_entity.dart';

CategoryEntity $CategoryEntityFromJson(Map<String, dynamic> json) {
  final CategoryEntity categoryEntity = CategoryEntity();
  final int? code = jsonConvert.convert<int>(json['code']);
  if (code != null) {
    categoryEntity.code = code;
  }
  final String? msg = jsonConvert.convert<String>(json['msg']);
  if (msg != null) {
    categoryEntity.msg = msg;
  }
  final List<CategoryData>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<CategoryData>(e) as CategoryData).toList();
  if (data != null) {
    categoryEntity.data = data;
  }
  return categoryEntity;
}

Map<String, dynamic> $CategoryEntityToJson(CategoryEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['code'] = entity.code;
  data['msg'] = entity.msg;
  data['data'] = entity.data.map((v) => v.toJson()).toList();
  return data;
}

extension CategoryEntityExtension on CategoryEntity {
  CategoryEntity copyWith({
    int? code,
    String? msg,
    List<CategoryData>? data,
  }) {
    return CategoryEntity()
      ..code = code ?? this.code
      ..msg = msg ?? this.msg
      ..data = data ?? this.data;
  }
}

CategoryData $CategoryDataFromJson(Map<String, dynamic> json) {
  final CategoryData categoryData = CategoryData();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    categoryData.id = id;
  }
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    categoryData.title = title;
  }
  final int? channelId = jsonConvert.convert<int>(json['channel_id']);
  if (channelId != null) {
    categoryData.channelId = channelId;
  }
  final int? parentId = jsonConvert.convert<int>(json['parent_id']);
  if (parentId != null) {
    categoryData.parentId = parentId;
  }
  return categoryData;
}

Map<String, dynamic> $CategoryDataToJson(CategoryData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['title'] = entity.title;
  data['channel_id'] = entity.channelId;
  data['parent_id'] = entity.parentId;
  return data;
}

extension CategoryDataExtension on CategoryData {
  CategoryData copyWith({
    int? id,
    String? title,
    int? channelId,
    int? parentId,
  }) {
    return CategoryData()
      ..id = id ?? this.id
      ..title = title ?? this.title
      ..channelId = channelId ?? this.channelId
      ..parentId = parentId ?? this.parentId;
  }
}